from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.common.by import By
service = ChromeService(executable_path='chromedriver.exe')
url = 'http://www.baidu.com'
browser = webdriver.Chrome(service=service)
browser.get(url)
# 获取id对象的属性
button = browser.find_element(by=By.ID,value='su')
class_attr = button.get_attribute("class")
print(class_attr)
#获取标签的名字
tag_name = button.tag_name
print(tag_name)
#获取文本内容
link = browser.find_element(by=By.LINK_TEXT,value='新闻')
print(link.text)